package com.evil.application.pojo.dto.button;

import cn.hutool.core.bean.BeanUtil;
import com.evil.application.pojo.entity.ApplicationButton;
import com.evil.common.application.enums.permission.PermissionStatusEnum;
import com.evil.common.core.enums.SwitchEnum;
import lombok.Data;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

@Data
public class ButtonBaseDTO {

    /**
     * 按钮id
     */
    private Long buttonId;

    /**
     * 按钮key
     */
    private String buttonKey;

    /**
     * 按钮名称
     */
    @NotBlank(message = "按钮名称不能为空")
    private String buttonName;

    /**
     * 按钮样式
     */
    @NotBlank(message = "样式不能为空")
    private String style;

    /**
     * 按钮触发动作
     */
    @NotNull(message = "触发动作不能为空")
    private Integer triggerAction;

    /**
     * 按钮链接
     */
    private String link;

    /**
     * 权限状态(0:全体, 1:指定)
     */
    @NotNull(message = "权限状态不能为空")
    private Integer permissionStatus;

    /**
     * 密码状态(0:关闭, 1:开)
     */
    @NotNull(message = "密码状态不能为空")
    private Integer passwordStatus;

    /**
     * 列表页展示(0:关闭, 1:开)
     */
    @NotNull(message = "列表页展示状态不能为空")
    private Integer inTable;

    /**
     * 详情页展示(0:关闭, 1:开)
     */
    @NotNull(message = "详情页展示状态不能为空")
    private Integer inDetail;

    public ButtonBaseDTO() {
        this.permissionStatus = PermissionStatusEnum.ALL.getId();
        this.passwordStatus = SwitchEnum.NO.getId();
    }

    public ButtonBaseDTO(ApplicationButton button) {
        BeanUtil.copyProperties(button, this);
    }

    public void copyProp(ApplicationButton button) {
        button.setButtonName(this.buttonName);
        button.setStyle(this.style);
        button.setTriggerAction(this.triggerAction);
        button.setLink(this.link);
        button.setPermissionStatus(this.permissionStatus);
        button.setPasswordStatus(this.passwordStatus);
    }
}
